{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# chipotle销售记录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:51:06.224373Z",
     "start_time": "2020-10-24T06:51:06.212378Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1.0.4'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as np\n",
    "np.__version__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:51:08.347673Z",
     "start_time": "2020-10-24T06:51:08.282711Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>order_id</th>\n",
       "      <th>quantity</th>\n",
       "      <th>item_name</th>\n",
       "      <th>choice_description</th>\n",
       "      <th>item_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Chips and Fresh Tomato Salsa</td>\n",
       "      <td>NaN</td>\n",
       "      <td>$2.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Izze</td>\n",
       "      <td>[Clementine]</td>\n",
       "      <td>$3.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Nantucket Nectar</td>\n",
       "      <td>[Apple]</td>\n",
       "      <td>$3.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Chips and Tomatillo-Green Chili Salsa</td>\n",
       "      <td>NaN</td>\n",
       "      <td>$2.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>Chicken Bowl</td>\n",
       "      <td>[Tomatillo-Red Chili Salsa (Hot), [Black Beans...</td>\n",
       "      <td>$16.98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4617</th>\n",
       "      <td>1833</td>\n",
       "      <td>1</td>\n",
       "      <td>Steak Burrito</td>\n",
       "      <td>[Fresh Tomato Salsa, [Rice, Black Beans, Sour ...</td>\n",
       "      <td>$11.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4618</th>\n",
       "      <td>1833</td>\n",
       "      <td>1</td>\n",
       "      <td>Steak Burrito</td>\n",
       "      <td>[Fresh Tomato Salsa, [Rice, Sour Cream, Cheese...</td>\n",
       "      <td>$11.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4619</th>\n",
       "      <td>1834</td>\n",
       "      <td>1</td>\n",
       "      <td>Chicken Salad Bowl</td>\n",
       "      <td>[Fresh Tomato Salsa, [Fajita Vegetables, Pinto...</td>\n",
       "      <td>$11.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4620</th>\n",
       "      <td>1834</td>\n",
       "      <td>1</td>\n",
       "      <td>Chicken Salad Bowl</td>\n",
       "      <td>[Fresh Tomato Salsa, [Fajita Vegetables, Lettu...</td>\n",
       "      <td>$8.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4621</th>\n",
       "      <td>1834</td>\n",
       "      <td>1</td>\n",
       "      <td>Chicken Salad Bowl</td>\n",
       "      <td>[Fresh Tomato Salsa, [Fajita Vegetables, Pinto...</td>\n",
       "      <td>$8.75</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4622 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      order_id  quantity                              item_name  \\\n",
       "0            1         1           Chips and Fresh Tomato Salsa   \n",
       "1            1         1                                   Izze   \n",
       "2            1         1                       Nantucket Nectar   \n",
       "3            1         1  Chips and Tomatillo-Green Chili Salsa   \n",
       "4            2         2                           Chicken Bowl   \n",
       "...        ...       ...                                    ...   \n",
       "4617      1833         1                          Steak Burrito   \n",
       "4618      1833         1                          Steak Burrito   \n",
       "4619      1834         1                     Chicken Salad Bowl   \n",
       "4620      1834         1                     Chicken Salad Bowl   \n",
       "4621      1834         1                     Chicken Salad Bowl   \n",
       "\n",
       "                                     choice_description item_price  \n",
       "0                                                   NaN     $2.39   \n",
       "1                                          [Clementine]     $3.39   \n",
       "2                                               [Apple]     $3.39   \n",
       "3                                                   NaN     $2.39   \n",
       "4     [Tomatillo-Red Chili Salsa (Hot), [Black Beans...    $16.98   \n",
       "...                                                 ...        ...  \n",
       "4617  [Fresh Tomato Salsa, [Rice, Black Beans, Sour ...    $11.75   \n",
       "4618  [Fresh Tomato Salsa, [Rice, Sour Cream, Cheese...    $11.75   \n",
       "4619  [Fresh Tomato Salsa, [Fajita Vegetables, Pinto...    $11.25   \n",
       "4620  [Fresh Tomato Salsa, [Fajita Vegetables, Lettu...     $8.75   \n",
       "4621  [Fresh Tomato Salsa, [Fajita Vegetables, Pinto...     $8.75   \n",
       "\n",
       "[4622 rows x 5 columns]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pf = np.read_csv('chipotle.tsv',sep='\\t')\n",
    "pf\n",
    "# type(pf)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:51:12.036593Z",
     "start_time": "2020-10-24T06:51:12.010610Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>order_id</th>\n",
       "      <th>quantity</th>\n",
       "      <th>item_name</th>\n",
       "      <th>choice_description</th>\n",
       "      <th>item_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Chips and Fresh Tomato Salsa</td>\n",
       "      <td>NaN</td>\n",
       "      <td>$2.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Izze</td>\n",
       "      <td>[Clementine]</td>\n",
       "      <td>$3.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Nantucket Nectar</td>\n",
       "      <td>[Apple]</td>\n",
       "      <td>$3.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Chips and Tomatillo-Green Chili Salsa</td>\n",
       "      <td>NaN</td>\n",
       "      <td>$2.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>Chicken Bowl</td>\n",
       "      <td>[Tomatillo-Red Chili Salsa (Hot), [Black Beans...</td>\n",
       "      <td>$16.98</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   order_id  quantity                              item_name  \\\n",
       "0         1         1           Chips and Fresh Tomato Salsa   \n",
       "1         1         1                                   Izze   \n",
       "2         1         1                       Nantucket Nectar   \n",
       "3         1         1  Chips and Tomatillo-Green Chili Salsa   \n",
       "4         2         2                           Chicken Bowl   \n",
       "\n",
       "                                  choice_description item_price  \n",
       "0                                                NaN     $2.39   \n",
       "1                                       [Clementine]     $3.39   \n",
       "2                                            [Apple]     $3.39   \n",
       "3                                                NaN     $2.39   \n",
       "4  [Tomatillo-Red Chili Salsa (Hot), [Black Beans...    $16.98   "
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#前五行数据\n",
    "pf.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:51:14.470769Z",
     "start_time": "2020-10-24T06:51:14.463772Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4622, 5)"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#打印形状\n",
    "pf.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:51:17.592457Z",
     "start_time": "2020-10-24T06:51:17.584462Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4622"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#获取列数\n",
    "pf.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:51:19.809250Z",
     "start_time": "2020-10-24T06:51:19.802254Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['order_id', 'quantity', 'item_name', 'choice_description',\n",
       "       'item_price'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#获取多少列\n",
    "pf.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:51:21.871689Z",
     "start_time": "2020-10-24T06:51:21.864695Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=4622, step=1)"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#索引\n",
    "pf.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:51:24.787500Z",
     "start_time": "2020-10-24T06:51:24.753515Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>quantity</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>item_name</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Chicken Bowl</th>\n",
       "      <td>761</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chicken Burrito</th>\n",
       "      <td>591</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chips and Guacamole</th>\n",
       "      <td>506</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Steak Burrito</th>\n",
       "      <td>386</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Canned Soft Drink</th>\n",
       "      <td>351</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chips</th>\n",
       "      <td>230</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Steak Bowl</th>\n",
       "      <td>221</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Bottled Water</th>\n",
       "      <td>211</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chips and Fresh Tomato Salsa</th>\n",
       "      <td>130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Canned Soda</th>\n",
       "      <td>126</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chicken Salad Bowl</th>\n",
       "      <td>123</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chicken Soft Tacos</th>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Side of Chips</th>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Veggie Burrito</th>\n",
       "      <td>97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Barbacoa Burrito</th>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Veggie Bowl</th>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Carnitas Bowl</th>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Barbacoa Bowl</th>\n",
       "      <td>66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Carnitas Burrito</th>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Steak Soft Tacos</th>\n",
       "      <td>56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6 Pack Soft Drink</th>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chips and Tomatillo Red Chili Salsa</th>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chicken Crispy Tacos</th>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chips and Tomatillo Green Chili Salsa</th>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Carnitas Soft Tacos</th>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Steak Crispy Tacos</th>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chips and Tomatillo-Green Chili Salsa</th>\n",
       "      <td>33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Steak Salad Bowl</th>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Nantucket Nectar</th>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chips and Tomatillo-Red Chili Salsa</th>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Barbacoa Soft Tacos</th>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chips and Roasted Chili Corn Salsa</th>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Izze</th>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Veggie Salad Bowl</th>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chips and Roasted Chili-Corn Salsa</th>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Barbacoa Crispy Tacos</th>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Barbacoa Salad Bowl</th>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chicken Salad</th>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Carnitas Crispy Tacos</th>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Veggie Soft Tacos</th>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Burrito</th>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Veggie Salad</th>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Carnitas Salad Bowl</th>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Bowl</th>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Steak Salad</th>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Salad</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Crispy Tacos</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chips and Mild Fresh Tomato Salsa</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Carnitas Salad</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Veggie Crispy Tacos</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                       quantity\n",
       "item_name                                      \n",
       "Chicken Bowl                                761\n",
       "Chicken Burrito                             591\n",
       "Chips and Guacamole                         506\n",
       "Steak Burrito                               386\n",
       "Canned Soft Drink                           351\n",
       "Chips                                       230\n",
       "Steak Bowl                                  221\n",
       "Bottled Water                               211\n",
       "Chips and Fresh Tomato Salsa                130\n",
       "Canned Soda                                 126\n",
       "Chicken Salad Bowl                          123\n",
       "Chicken Soft Tacos                          120\n",
       "Side of Chips                               110\n",
       "Veggie Burrito                               97\n",
       "Barbacoa Burrito                             91\n",
       "Veggie Bowl                                  87\n",
       "Carnitas Bowl                                71\n",
       "Barbacoa Bowl                                66\n",
       "Carnitas Burrito                             60\n",
       "Steak Soft Tacos                             56\n",
       "6 Pack Soft Drink                            55\n",
       "Chips and Tomatillo Red Chili Salsa          50\n",
       "Chicken Crispy Tacos                         50\n",
       "Chips and Tomatillo Green Chili Salsa        45\n",
       "Carnitas Soft Tacos                          40\n",
       "Steak Crispy Tacos                           36\n",
       "Chips and Tomatillo-Green Chili Salsa        33\n",
       "Steak Salad Bowl                             31\n",
       "Nantucket Nectar                             29\n",
       "Chips and Tomatillo-Red Chili Salsa          25\n",
       "Barbacoa Soft Tacos                          25\n",
       "Chips and Roasted Chili Corn Salsa           23\n",
       "Izze                                         20\n",
       "Veggie Salad Bowl                            18\n",
       "Chips and Roasted Chili-Corn Salsa           18\n",
       "Barbacoa Crispy Tacos                        12\n",
       "Barbacoa Salad Bowl                          10\n",
       "Chicken Salad                                 9\n",
       "Carnitas Crispy Tacos                         8\n",
       "Veggie Soft Tacos                             8\n",
       "Burrito                                       6\n",
       "Veggie Salad                                  6\n",
       "Carnitas Salad Bowl                           6\n",
       "Bowl                                          4\n",
       "Steak Salad                                   4\n",
       "Salad                                         2\n",
       "Crispy Tacos                                  2\n",
       "Chips and Mild Fresh Tomato Salsa             1\n",
       "Carnitas Salad                                1\n",
       "Veggie Crispy Tacos                           1"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#根据销售物品名字,和价格,根据物品进行分组，然后统计后,再根据数量降序显示\n",
    "pf[['item_name','quantity']].groupby(by=['item_name']).sum().sort_values(by=['quantity'],ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:51:28.808243Z",
     "start_time": "2020-10-24T06:51:28.796247Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "50"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#多少种产品\n",
    "pf.item_name.nunique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:51:31.604846Z",
     "start_time": "2020-10-24T06:51:31.594850Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0                                                     NaN\n",
       "1                                            [Clementine]\n",
       "2                                                 [Apple]\n",
       "3                                                     NaN\n",
       "4       [Tomatillo-Red Chili Salsa (Hot), [Black Beans...\n",
       "                              ...                        \n",
       "4617    [Fresh Tomato Salsa, [Rice, Black Beans, Sour ...\n",
       "4618    [Fresh Tomato Salsa, [Rice, Sour Cream, Cheese...\n",
       "4619    [Fresh Tomato Salsa, [Fajita Vegetables, Pinto...\n",
       "4620    [Fresh Tomato Salsa, [Fajita Vegetables, Lettu...\n",
       "4621    [Fresh Tomato Salsa, [Fajita Vegetables, Pinto...\n",
       "Name: choice_description, Length: 4622, dtype: object"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pf['choice_description']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:51:34.444283Z",
     "start_time": "2020-10-24T06:51:34.433293Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       1\n",
       "1       1\n",
       "2       1\n",
       "3       1\n",
       "4       2\n",
       "       ..\n",
       "4617    1\n",
       "4618    1\n",
       "4619    1\n",
       "4620    1\n",
       "4621    1\n",
       "Name: quantity, Length: 4622, dtype: int64"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pf['quantity']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:51:36.770760Z",
     "start_time": "2020-10-24T06:51:36.732781Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[Diet Coke]    134\n",
       "[Coke]         123\n",
       "[Sprite]        77\n",
       "Name: choice_description, dtype: int64"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "##在choice_description中，下单次数最多的商品是什么？\n",
    "pf[['choice_description','quantity']].groupby(by=['choice_description']).sum().sort_values(by=['quantity'],ascending=False)\n",
    "pf['choice_description'].value_counts().head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:51:44.821442Z",
     "start_time": "2020-10-24T06:51:44.812449Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4972"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#一共有多少商品被下单？\n",
    "pf['quantity'].sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:54:20.756691Z",
     "start_time": "2020-10-24T06:54:20.732705Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0        2.39\n",
       "1        3.39\n",
       "2        3.39\n",
       "3        2.39\n",
       "4       16.98\n",
       "        ...  \n",
       "4617    11.75\n",
       "4618    11.75\n",
       "4619    11.25\n",
       "4620     8.75\n",
       "4621     8.75\n",
       "Name: item_price, Length: 4622, dtype: float64"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#将item_price转换为浮点数\n",
    "#货币符号后取起\n",
    "# pf['item_price'].str.split('$').str\n",
    "pf['item_price']=pf['item_price'].apply(lambda x: x.replace(\",\",\"\").replace(\"$\",\"\")).astype(\"float64\")\n",
    "pf['item_price']\n",
    "# type(pf['item_price']) \n",
    "# Series 就是一维数组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:55:59.405901Z",
     "start_time": "2020-10-24T06:55:59.396907Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "39237.02"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#在该数据集对应的时期内，收入(revenue)是多少？\n",
    "(pf['quantity'] * pf['item_price']).sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:57:44.203706Z",
     "start_time": "2020-10-24T06:57:44.195714Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1834"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#在该数据集对应的时期内，一共有多少订单？\n",
    "pf['order_id'].nunique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:59:00.254051Z",
     "start_time": "2020-10-24T06:59:00.231065Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4622"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 一个order_id 可以对应多个商品\n",
    "# unique 返回所有的唯一值 返回数组\n",
    "# nunique 统计唯一order_id的数量 统计值\n",
    "# count 统计所有order_id的数量(包括重复order_id) 统计值\n",
    "pf['order_id'].count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T06:57:17.324473Z",
     "start_time": "2020-10-24T06:57:17.293491Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<bound method Series.isna of 0          1\n",
       "1          1\n",
       "2          1\n",
       "3          1\n",
       "4          2\n",
       "        ... \n",
       "4617    1833\n",
       "4618    1833\n",
       "4619    1834\n",
       "4620    1834\n",
       "4621    1834\n",
       "Name: order_id, Length: 4622, dtype: int64>"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pf['order_id'].isna"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-10-24T07:07:00.423699Z",
     "start_time": "2020-10-24T07:07:00.397715Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "item_price_sum    21.394231\n",
       "dtype: float64"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#每一单(order)对应的平均总价是多少？ -- 客单价\n",
    "pf['item_price_sum'] = pf['quantity'] * pf['item_price']\n",
    "(pf[['order_id','item_price_sum']].groupby(by=['order_id']).sum()).mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 必胜客 和 麦当劳 "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
